var t = getApp();

Page({
    data: {
        form: {
            mobile: "",
            code: "",
            captcha: ""
        },
        action_name: "绑定",
        codetext: "获取短信验证码",
        start1: !1,
        imgcode: ""
    },
    onLoad: function(t) {},
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    captchainp: function(t) {
        var a = t.detail.value;
        this.setData({
            "form.captcha": a.trim()
        });
    },
    mobileinp: function(t) {
        var a = t.detail.value;
        this.setData({
            "form.mobile": a.trim()
        });
    },
    codeinp: function(t) {
        var a = t.detail.value;
        this.setData({
            "form.code": a.trim()
        });
    },
    sendCode: function(t) {
        if (this.data.start1) return !1;
        var a = 60, e = this;
        e.setData({
            start1: !0,
            codetext: "(" + a + ")秒后重新获取"
        });
        var o = setInterval(function() {
            e.setData({
                codetext: "(" + --a + ")秒后重新获取"
            });
        }, 1e3);
        setTimeout(function() {
            e.setData({
                codetext: "获取短信验证码",
                start1: !1
            }), clearInterval(o);
        }, 6e4), e.verificationCode(o);
    },
    verificationCode: function(a) {
        var e = this;
        if (t._isTextEmpty(this.data.form.captcha) && this.data.imgcode) wx.showToast({
            icon: "none",
            title: "请填图形验证码",
            duration: 1500
        }), e.setData({
            codetext: "获取短信验证码",
            start1: !1
        }), clearInterval(a); else if (t._isTextEmpty(this.data.form.mobile)) wx.showToast({
            icon: "none",
            title: "请填写手机号",
            duration: 1500
        }), e.setData({
            codetext: "获取短信验证码",
            start1: !1
        }), clearInterval(a); else {
            var o = t.getNetAddresss("member.register.sendWithdrawCode");
            o += "&mobile=" + this.data.form.mobile, o += "&captcha=" + this.data.form.captcha, 
            o += "&code=" + this.data.form.code, t._getNetWork({
                url: o,
                success: function(t) {
                    var a = t.data;
                    1 == a.result ? wx.showToast({
                        icon: "none",
                        title: "已发送",
                        duration: 1500
                    }) : (wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    }), e.setData({
                        "form.captcha": ""
                    }), e.getimgdata());
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    getimgdata: function() {
        var a = this, e = t.getNetAddresss("home-page.index");
        t._getNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                1 == e.result && e.data.captcha && a.setData({
                    imgcode: e.data.captcha.img
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    alterAction: function() {
        if (t._isTextEmpty(this.data.form.mobile)) wx.showToast({
            icon: "none",
            title: "手机号码不能为空",
            duration: 1500
        }); else if (t._isMoblie(this.data.form.mobile)) wx.showToast({
            icon: "none",
            title: "请输入正确的手机号",
            duration: 1500
        }); else if (t._isTextEmpty(this.data.form.code)) wx.showToast({
            icon: "none",
            title: "请填写验证码",
            duration: 1500
        }); else if (this.data.imgcode && t._isTextEmpty(this.data.form.captcha)) wx.showToast({
            icon: "none",
            title: "图形验证码不能为空",
            duration: 1500
        }); else {
            var a = t.getNetAddresss("member.member.bindWithdrawMobile");
            t._postNetWork({
                url: a,
                showToastIn: !1,
                data: this.data.form,
                success: function(t) {
                    var a = t.data;
                    1 == a.result ? wx.showToast({
                        title: a.msg,
                        icon: "none",
                        duration: 1500,
                        success: function() {
                            setTimeout(function() {
                                wx.navigateBack({
                                    delta: 1
                                });
                            }, 1500);
                        }
                    }) : wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {}
            });
        }
    }
});